package com.lemon.smartsafety.ui.adapter.notice;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.lemon.smartsafety.R;
import com.lemon.smartsafety.entity.notice.NoticeInfoVo;
import com.lemon.smartsafety.listener.RecyclerTClickListener;
import com.lemon.smartsafety.utils.common.DateUtils;
import com.lemon.smartsafety.utils.common.StringUtils;

import java.util.List;

import kale.adapter.LemonRcvAdapter;
import kale.adapter.item.AdapterItem;

/**
 * Created by Cooliean on 16/3/29.
 */
public class NoticeSentAdapter extends LemonRcvAdapter<NoticeInfoVo> {
    private RecyclerTClickListener<NoticeInfoVo> mListener;

    public NoticeSentAdapter(@Nullable List<NoticeInfoVo> data) {
        super(data);
    }

    public NoticeSentAdapter(List<NoticeInfoVo> data, RecyclerTClickListener<NoticeInfoVo> listener) {
        super(data);
        this.mListener = listener;
    }

    @NonNull
    @Override
    public AdapterItem createItem(Object type) {
        return new NoticeSentItem();
    }

    public class NoticeSentItem implements AdapterItem<NoticeInfoVo> {
        LinearLayout ripple;
        TextView tvItemTitle;
        TextView tvSentTime;
        TextView tvReadStatus;




        private NoticeInfoVo mData;
        private int          mPosition;


        @Override
        public int getLayoutResId() {
            return R.layout.item_notice_sent_list;
        }

        @Override
        public void bindViews(View root) {
            ripple = (LinearLayout) root.findViewById(R.id.ripple);
            tvItemTitle = (TextView) root.findViewById(R.id.tv_item_title);
            tvSentTime = (TextView) root.findViewById(R.id.tv_sent_time);
            tvReadStatus = (TextView) root.findViewById(R.id.tv_read_status);
        }

        @Override
        public void setViews() {
            ripple.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (mListener != null) {
                        mListener.onItemClick(mData, mPosition);
                    }
                }
            });
        /*    ripple.setOnRippleCompleteListener(new RippleView.OnRippleCompleteListener() {
                @Override
                public void onComplete(RippleView rippleView) {
                    if (mListener != null) {
                        mListener.onItemClick(mData, mPosition);
                    }
                }
            });*/
        }

        @Override
        public void handleData(NoticeInfoVo data, int position) {
            mData = data;
            mPosition = position;
            tvItemTitle.setText(StringUtils.nullValue(data.getTitle()));


            tvSentTime.setText(DateUtils.getFormatDateStringWithDateString(data.getRecordDate(), DateUtils.dateFormatYMDHM));

            tvReadStatus.setText(String.format("%s/%s", StringUtils.nullValue(data.getReaderCount(), "0"), StringUtils.nullValue(data.getDueReaerCount(), "0")));

        }
    }
}
